Topic: DMD0367 Interrupt Service Routines |
|
An interrupt is a signal generated by some event external to the CPU, which causes the CPU to stop what it is doing (stop executing the code it is currently running) and jump to a separate piece of code designed by the programmer to deal with the event which generated the interrupt request. This interrupt handling code is called an ISR (interrupt service routine). When the ISR is finished, the CPU returns to the code that was running prior to the interrupt, which then resumes running with no awareness that it has been preempted by the interrupt code. It is this ability to run the appropriate code for an external event at any point in time that is both the chief benefit of, and the potential source of difficulties from, interrupts.
In the Do-more CPUs, an interrupt service routine (ISR) is a code-block, whose execution is triggered by the reception of an Interrupt Trigger, which is configured through the System Configuration or through the INTCONFIG - Interrupt Configuration Editor. Interrupt Triggers define the external hardware event or timed event that constitutes the Interrupt, and associates an Interrupt Service Routine (ISR) that will be executed when that Interrupt Trigger is fired. Cautions when Using InterruptsBecause ISRs are interrupting all of the normal processing that happens during a PLC scan - this includes all communication processes - it is imperative that the ladder logic in the ISR be kept to a minimum. If possible use only contacts, coils and Math operations.
Interrupts are intended to be used to manage processes that require precision, either by minimizing the latency from when a signal is received until the code that handles that signal is executed, or by performing operations at very precise time intervals. They are not intended to prioritize the execution of lots of ladder logic. When done properly Interrupts can be a great tool to handle intra-scan events that need immediate servicing. Done improperly they can wreak havoc on your PLC scan. To that end we've compiled a list of things that Interrupts can and cannot do to help you use them wisely.
Interrupt Overload DetectionConfiguring interrupts that will happen very frequently, or having multiple interrupts that will consume a significant amount of time each time they process can consume enough of the scan time to trip the watchdog timer. To help mitigate the potential of this happening, the CPU will accumulate the runtime of all of the interrupt routines during a scan, and if that accumulated time exceeds 10ms the CPU will suspend interrupt processing for the remainder of that scan and set $ISROverload (ST155) ON to indicate the configured interrupts are consuming too much of the CPU scan. Normal interrupt processing will resume on the following scan.
|
|
Interrupt Service Routine Code-Block ConfigurationAny time a new Interrupt Service Routine is created the following dialog will open where you will specify the operating parameters of the code-block that is associated with the ISR.
Name - the name of the code block that is executed when the associated Interrupt Trigger event occurs. This name will also be used as the name of the structure you will use to interact with this ISR in the ladder logic of a project. The ISR name can be 1 to 16 characters in length and consist of any combination of alphanumeric characters and underscores ('_', 'a-z', 'A-Z', 0-9), no spaces or punctuation marks are allowed, and must begin with a letter or an underscore.
Retentive Interrupt Structure (affects System Configuration) - enable this selection to make the ISR's structure retentive, meaning the structure and all of its member fields will retain their values through a power-cycle.
ISR ID: xx - a unique number assigned when the ISR is created. There can be up to 32 ISRs in a project.
Notice the TimeSlice option is missing. This is because Interrupt Service Routines do not allow the use of looping instructions (FOR / NEXT, WHILE / WEND, REPEAT / UNTIL, GOTO / LABEL).
These optional selections control accessibility and visibility of a code-block within Do-more Designer. The programmer can select to secure the contents of user-created code-blocks from being viewed and / or edited by means of a password and optionally encrypting the code-block contents. This dialog will show the current state of the protection and allow the programmer to set the protection level that will be enforced once the dialog is closed or the project is closed.
Click Set Protection Level to save the protection level changes.
Click Cancel to exit without saving any protection level changes. |
|
Interrupt Service Routine Code-Block Structure FieldsEach Interrupt Service Routine has an associated code-block, and that code block has an associated structure with fields that are used interact with the ISR from the ladder logic:
.HasRun - (Read / Write) - a Bit that will be ON if the ISR was run at least one time since the last Program -to- Run mode change.
.Inhibit - (Read / Write) - a Bit that can be set ON to prevent the ISR from being executed when the Interrupt Trigger fires.
.RunCounter - (Read / Write) - a Word location that contains the number of time the ISR has been executed since the last Program -to- Run mode change.
.Latency - (Read / Write) - a Word location that contains the amount of time (in microseconds) between when the Interrupt Trigger was fired and the execution of the ISR began.
.ExecutionTime - (Read / Write) - a Word location that contains the amount of time (in microseconds) the ISR took to execute. Manually Suspending All InterruptsInterrupt processing can be suspended through the use of the Suspend Interrupts (INTSUSPEND) instruction. which disables all interrupt processing in the CPU - both external hardware events and timed events.
Normal Interrupt Processing can be restarted with the INTRESUME - Resume Interrupts instruction. Changing Interrupt Configuration at RuntimeNew Interrupt Triggers can be created, and the configuration of existing Interrupt Triggers can be changed at runtime through the INTCONFIG - Interrupt Configuration Editor instruction.
Existing Interrupt Triggers can be deleted with the INTDECONFIG - Deconfigure Interrupt instruction.
|
|
See Also:
EXIT - EXIT This Program or Task
RETC - Conditional Return Back to Call
INTCONFIG - Interrupt Configuration Editor INTDECONFIG - Deconfigure Interrupt INTSUSPEND - Suspend Interrupt
|
|
Related Topics:Related Instruction Topics:
ENDC - Conditional End of Code Block
RESTART - Restart Program or Task
SUSPEND - Suspend Program or Task
|
|